package com.util;

import javax.annotation.Resource;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Resource
@Component
public class SpringContextUtils implements ApplicationContextAware
{
  private static ApplicationContext applicationContext;
  
  public static Object getBean(String name)
    throws BeansException
  {
    return applicationContext.getBean(name);
  }

  public static <T> T getBean(Class<T> type)
  {
    return (T)applicationContext.getBean(type);
  }
  
  public void setApplicationContext(ApplicationContext context) throws BeansException
  {
	  SpringContextUtils.applicationContext = context;
  }
}

 